""" Defines the User repository """

from models import Portfolio


class PortfolioRepository:
    """ The repository for the portfolio model """

    @staticmethod
    def get(code):
        """ Query a portfolio by last and first name """
        print(code)
        return Portfolio.query.filter_by(code=code).one()

    def update(code, name, price):
        """ Update a portfolio's age """
        portfolio = self.get(code, name)
        portfolio.price = price

        return portfolio.save()

    @staticmethod
    def create(code, name, price):
        """ Create a new portfolio """
        portfolio = Portfolio(code=code, name=name, price=price)

        return portfolio.save()
